import { RequestHandler } from "express";
import { DataStore } from "../../data";
import { UserDetails } from "../../model/shared/userDetails";
import { User } from "../../data/types";

export const apiGetUserInfor: RequestHandler = (req, res, next) => {
  res.json(DataStore.user.map(item =>
    item as User
  ))
}

export const apiGetUserInforDetail: RequestHandler = (req, res, next) => {

  DataStore.user.forEach(item => {
    if (item.id.toString() == req.params.id) {
      let todos=   DataStore.todo.filter(todo=>todo.id==item.id )
     
      res.json(new UserDetails(item,todos))
    }
  })

  res.status(404).json({ status: "failed", message: "user id NorFound" })
}
